$(function() {
    $("#js-next-step").on('click',function(){
        $("#js-register").submit();//填写手机号提交表单
    });
    $("#js-register").on('submit', function() {//提交手机号表单
        var phone = $("#js-register").find('input[name="phone"]').val();
        var isOk = checkPhone(phone);
        if(isOk != true) {
            alert(isOk);
            return false;
        }
        $.ajax({
            'url': '/Ajax/Passport/checkPhoneAndSendMessageVerify',//判断手机号后发送验证码
            data: {phone: phone},
            async:false,
            type: 'post',
            dataType: 'json',
            success: function (d) {
                if (d.error) {
                    alert(d.data)
                } else {
                    window.location.href = '/Passport/Register2?phone=' + phone;
                }
            }
        });
        return false;
    });
    $("#js-next-steps").on('click',function(){//提交密码
        var verify = $("#js-register-two").find('input[name="verify"]').val();
        var password = $("#js-register-two").find('input[name="password"]').val();
        var repassword = $("#js-register-two").find('input[name="repassword"]').val();
        if(!password) {
            alert('请输入密码！');
            return false;
        }
        if(password.length < 6) {
            alert('请输入6位或以上密码！');
            return false;
        }
        if(!repassword) {
            alert('请输入确认密码！');
            return false;
        }
        if(repassword != password) {
            alert('两次密码输入不一致！');
            return false;
        }
        var isOk = false;
        $.ajax({
            async:false,
            'url': '/Ajax/Passport/checkVerifyByPhone',//判断手机号
            data: {
                phone: phone,
                verify: verify
            },
            type: 'post',
            dataType: 'json',
            success: function (d) {
                if (d.error) {
                    alert(d.data);
                } else {
                    isOk = true;
                }
            }
        });
        if(isOk) {
            $("#js-register-two").submit();
        }
    });
    $("#complete").on('click',function(){
        var phone = $("#js-register-three").find('input[name="phone"]').val();
        var password = $("#js-register-three").find('input[name="password"]').val();
        var nickname = $("#js-register-three").find('input[name="nickname"]').val();
        $.ajax({
            async:false,
            'url': '/Ajax/Passport/registerByPhone',//判断手机号
            data: {
                phone: phone,
                password: password,
                nickname: nickname
            },
            type: 'post',
            dataType: 'json',
            success: function (d) {
                if (d.error) {
                    alert(d.data);
                } else {
                    window.location.href = '/';
                }
            }
        });
    })
});